package com.excel.util;

import com.excel.func.FuncInterface;
import java.util.Map;

/**
 * @author User
 */
public class FuncUtil {

    private FuncUtil() {
        throw new IllegalStateException("Utility class");
    }

    public static void handleIfTrue(boolean condition, Runnable runnable) {
        if (condition) {
            runnable.run();
        }
    }

    public static void throwIfTrue(boolean condition, String errorMsg) {
        if (condition) {
            throw new RuntimeException(errorMsg);
        }
    }

    public static void throwIfTrue(boolean condition, Runnable runnable) {
        if (condition) {
            runnable.run();
        }
    }


    public static Map throwApp(boolean condition) {
        if (condition) {
            return Map.of("isSuccess", true, "msg", "操作成功");
        } else {
            return Map.of("isSuccess", false, "msg", "操作失败");
        }
    }

    public static FuncInterface judge(boolean b) {
        return (trueHandle, falseHandle) -> {
            if (b) {
                trueHandle.run();
            } else {
                falseHandle.run();
            }
        };
    }


}
